<template>
	<view class="page-index">
		<!-- 启动页 -->
		<u-popup :show="isShowAgreeMod" mode="center" :round="10">
			<view class="padding" style="width: 600rpx;">
				<view class="title">提示</view>
				<view class="agree-tips">
					尊敬的用户，我们十分重视您的个人信息安全，在您使用APP服务之前，请务必认真阅读
					<text @click="toAgree(1)" class="theme-color">《用户协议》</text>以及
					<text @click="toAgree(2)" class="theme-color">《隐私政策》</text>的全部内容。我们需要获得您的同意方可为您提供优质服务。
				</view>
				<view class="btn-list flex justify-around align-center">
					<view @click="agreeRead(0)" class="agree-btn">暂不同意</view>
					<view @click="agreeRead(1)" class="agree-btn theme-color">同意</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				result: '',
				version: '',
				isShowAgreeMod: false,
			}
		},
		onLoad() {
			this.judgeFirstOpen();
		},
		methods: {
			// 同意拒绝 协议
			agreeRead(e) {
				switch (e) {
					case 0:
						// #ifdef APP-PLUS  
						plus.ios.import("UIApplication").sharedApplication().performSelector("exit"); // ios不同意协议，退出app
						this.isShowAgreeMod = false;
						// #endif
						break;
					case 1:
						this.isShowAgreeMod = false;
						uni.reLaunch({
							url: './netError'
						})
						break;
					default:
						break;
				}
			},

			// 协议详情
			toAgree(e) {
				switch (e) {
					case 1:
						let userAgr = 'http://www.xxxxx.com/xieyi/userAgr.html';
						// console.log(userAgr);
						uni.navigateTo({
							url: '../webview/webview?url=' + userAgr
						})
						break;
					case 2:
						if (uni.getSystemInfoSync().platform == "ios") {
							uni.navigateTo({
								url: '../webview/webview?url=http://www.xxxxx.com/xieyi/privacyPolicy.html'
							})
						} else {
							uni.navigateTo({
								url: '../webview/webview?url=http://www.xxxxx.com/xieyi/userPrivacyPolicy.html'
							})
						}
						break;
					default:
						break;
				}
			},

			//	判断是否第一次打开APP，第一次打开则可以做相应处理
			judgeFirstOpen() {
				const hasOpenApp = uni.getStorageSync('hasOpenApp');
				if (hasOpenApp) {
					// console.log('已经打开过了');
					this.checkLogin();
				} else {
					// console.log('第一次打开,协议授权');
					if (uni.getSystemInfoSync().platform == "android") {
						uni.reLaunch({
							url: './netError'
						})
					} else if (uni.getSystemInfoSync().platform == "ios") {
						this.isShowAgreeMod = true;
					}
				}
			},

			// 校验登录状态
			checkLogin() {
				const value = uni.getStorageSync('hasLogin');
				console.log('是否登录: ' + value);
				if (value) {
					uni.switchTab({
						url: '../tabbar/home'
					})
				} else {
					//进入登录页面
					uni.reLaunch({
						url: '/pages/login/login'
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page-index {
		
		.title{
			margin-bottom: 30rpx;
			text-align: center;
		}
		
		.agree-tips{
			font-size: 28rpx;
			line-height: 2;
			text-indent: 2em;
		}
		
		.btn-list{
			margin-top: 30rpx;
		}
		.agree-btn{
			color: #888;
			font-size: 28rpx;
		}
		.theme-color{
			color: blue;
		}
	}
</style>